package model;

import java.io.Serializable;

import javax.persistence.*;

import java.util.ArrayList;
import java.util.List;

/**
 * The persistent class for the user database table.
 * 
 */
@NamedQueries({
        @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
        @NamedQuery(name = "User.findById", query = "SELECT u FROM User u WHERE u.id = :id")
})
@Entity
@Table(name = "rmt_user")
public class User implements Serializable {


	/**
	 * 
	 */
	private static final long serialVersionUID = 6622412175527970547L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int id;

	@Column(nullable = false)
	private String email;

	@Column(nullable = false)
	private int isactive;

	@Column(nullable = false)
	private String name;

	@Column(nullable = false)
	private String password;

	@Column(nullable = false)
	private String username;

	// bi-directional many-to-one association to Response
	@OneToMany(mappedBy = "user")
	private List<Response> responses;

	// bi-directional many-to-one association to Ticket
	@OneToMany(mappedBy = "user")
	private List<Ticket> tickets;

	// bi-directional many-to-one association to Usertype
	@ManyToOne
	@JoinColumn(name = "idUsertype")
	private Usertype usertype;

	// bi-directional many-to-one association to Domain
	@ManyToOne
	@JoinColumn(name = "idDomain")
	private Domain domain;

	// bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name = "replacedBy")
	private User user;

	// bi-directional one-to-many association to User
	@OneToMany(mappedBy = "user")
	private List<User> users;

	// bi-directional one-to-many association to Userlog
	@OneToMany(mappedBy = "user")
	private List<Userlog> userlogs;

    // bi-directional one-to-many association to Leave
    @OneToMany(mappedBy = "user")
    private List<Leave> leaves = new ArrayList<>();

	private transient String status;
	private transient String ip;

	/**
	 * @return
	 */
	public String getStatus() {
		return status;
	}

	/**
	 * @param status
	 */
	public void setStatus(String status) {
		this.status = status;
	}

	/**
	 * @return
	 */
	public String getIp() {
		return ip;
	}

	/**
	 * @param ip
	 */
	public void setIp(String ip) {
		this.ip = ip;
	}

	public User() {
	}

	/**
	 * @return
	 */
	public int getId() {
		return this.id;
	}

	/**
	 * @param id
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @return
	 */
	public String getEmail() {
		return this.email;
	}

	/**
	 * @param email
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return
	 */
	public int getIsactive() {
		return this.isactive;
	}

	/**
	 * @param isactive
	 */
	public void setIsactive(int isactive) {
		this.isactive = isactive;
	}

	/**
	 * @return
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return
	 */
	public String getPassword() {
		return this.password;
	}

	/**
	 * @param password
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return
	 */
	public String getUsername() {
		return this.username;
	}

	/**
	 * @param username
	 */
	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * @return
	 */
	public List<Response> getResponses() {
		return this.responses;
	}

	/**
	 * @param responses
	 */
	public void setResponses(List<Response> responses) {
		this.responses = responses;
	}

	/**
	 * @param respons
	 * @return
	 */
	public Response addRespons(Response respons) {
		if (getResponses() == null) responses = new ArrayList<>();
		getResponses().add(respons);
		respons.setUser(this);

		return respons;
	}

	/**
	 * @param respons
	 * @return
	 */
	public Response removeRespons(Response respons) {
		getResponses().remove(respons);
		respons.setUser(null);

		return respons;
	}

	/**
	 * @return
	 */
	public List<Ticket> getTickets() {
		return this.tickets;
	}

	/**
	 * @param tickets
	 */
	public void setTickets(List<Ticket> tickets) {
		this.tickets = tickets;
	}

	/**
	 * @param ticket
	 * @return
	 */
	public Ticket addTicket(Ticket ticket) {
		if (getTickets() == null) tickets = new ArrayList<>();
		ticket.setUser(this);

		return ticket;
	}

	/**
	 * @param ticket
	 * @return
	 */
	public Ticket removeTicket(Ticket ticket) {
		getTickets().remove(ticket);
		ticket.setUser(null);

		return ticket;
	}

	/**
	 * @return
	 */
	public Usertype getUsertype() {
		return this.usertype;
	}

	/**
	 * @param usertype
	 */
	public void setUsertype(Usertype usertype) {
		this.usertype = usertype;
	}

	/**
	 * @return
	 */
	public Domain getDomain() {
		return this.domain;
	}

	/**
	 * @param domain
	 */
	public void setDomain(Domain domain) {
		this.domain = domain;
	}

	/**
	 * @return
	 */
	public User getUser() {
		return this.user;
	}

	/**
	 * @param user
	 */
	public void setUser(User user) {
		this.user = user;
	}

	/**
	 * @return
	 */
	public List<User> getUsers() {
		return this.users;
	}

	/**
	 * @param users
	 */
	public void setUsers(List<User> users) {
		this.users = users;
	}

	/**
	 * @param user
	 * @return
	 */
	public User addUser(User user) {
		if (getUsers() == null) users = new ArrayList<>();
		getUsers().add(user);
		user.setUser(this);

		return user;
	}

	/**
	 * @param user
	 * @return
	 */
	public User removeUser(User user) {
		getUsers().remove(user);
		user.setUser(null);

		return user;
	}

	/**
	 * @return
	 */
	public List<Userlog> getUserlogs() {
		return this.userlogs;
	}

	/**
	 * @param userlogs
	 */
	public void setUserlogs(List<Userlog> userlogs) {
		this.userlogs = userlogs;
	}

	/**
	 * @param userlog
	 * @return
	 */
	public Userlog addUserlog(Userlog userlog) {
		
		if (getUserlogs() == null) userlogs = new ArrayList<>();
		getUserlogs().add(userlog);
		userlog.setUser(this);

		return userlog;
	}

	/**
	 * @param userlog
	 * @return
	 */
	public Userlog removeUserlog(Userlog userlog) {
		getUserlogs().remove(userlog);
		userlog.setUser(null);

		return userlog;
	}

    public List<Leave> getLeaves() {
        return leaves;
    }

    public void setLeaves(List<Leave> leaves) {
        this.leaves = leaves;
    }
}